//
//  FeedBackTableViewController.m
//  ITHome
//
//  Created by lanou3g on 15/7/16.
//  Copyright (c) 2015年 YAX. All rights reserved.
//

#import "FeedBackTableViewController.h"

@interface FeedBackTableViewController ()<UITextViewDelegate>

@property (nonatomic, strong) UITextView *textView1;
@property (nonatomic, strong) UITextView *textView2;
@property (nonatomic, strong) UILabel *textLable1;
@property (nonatomic, strong) UILabel *textLable2;

@end

@implementation FeedBackTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.tableFooterView = [[UIView alloc] init]; // 取消行
    [self loadNavigationIndfo];

    
}
#pragma mark - 设置导航栏
- (void)loadNavigationIndfo
{
    self.navigationController.navigationBar.barTintColor = [UIColor RGBColor:71 green:128 blue:208 alpha:1];
    
    self.navigationItem.title = @"意见反馈";
    // 返回
    UIBarButtonItem *leftBackButton = [UIBarButtonItem itemWithTarget:self Action:@selector(backAction) image:@"home_back" highImage:@"home_back_highlighted"];
    self.navigationItem.leftBarButtonItem = leftBackButton;
    
    // 保存
    UIBarButtonItem *rightSaveButton  = [UIBarButtonItem itemWithTarget:self Action:@selector(sendAction) title:@"发送"];
    self.navigationItem.rightBarButtonItem = rightSaveButton;
    
    // 标题
    [[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
    
}

#pragma mark - 返回按钮触发事件
- (void)backAction
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

#pragma mark - 保存
- (void)sendAction
{
    [ProgressHUD progressHUD:self.view labelText:@"发送成功,感谢反馈"];
    [_textView1 resignFirstResponder];
    [_textView2 resignFirstResponder];
    [self performSelector:@selector(backAction) withObject:nil afterDelay:1.0f];
}

#pragma mark -- 设置每个分区的行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 3;
}

#pragma mark -- 自定义cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    if (indexPath.row == 0)
    {
        self.textView1.frame = CGRectMake(10, 5, cell.contentView.bounds.size.width-20, 90);
        _textView1.hidden = NO;
        _textView1.delegate = self;
        [cell.contentView addSubview:_textView1];
        [self getTextLableView:self.textLable1 InTextView:self.textView1 WithText:@"请简单描述你所遇到的问题或建议,还可以添加QQ或者微信账号229201093与我们及时沟通哟~\n"];

    }
    else if (indexPath.row == 1)
    {
        self.textView2.frame = CGRectMake(10, 5, cell.contentView.width - 20, 40);
        _textView2.hidden = NO;
        _textView2.delegate = self;
        [cell.contentView addSubview:_textView2];
        [self getTextLableView:self.textLable2 InTextView:self.textView2 WithText:@"填写 QQ 电话 或 邮箱"];
    }
    else
    {
        cell.textLabel.numberOfLines = 0;
        cell.textLabel.font = [UIFont systemFontOfSize:13];
        cell.textLabel.text = @"上述内容仅对[IT家园]工作人员可见，工作人员看到会及时与你沟通并解决问题。";
    }
    return cell;
}

- (void)getTextLableView:(UILabel *)textLable InTextView:(UITextView *)textView WithText:(NSString *)text
{
    textLable.frame = CGRectMake(textView.x , textView.y, textView.width - 10, textView.height);
    textLable.text = text;
    textLable.numberOfLines = 0;
    textLable.textAlignment = NSTextAlignmentCenter;
    textLable.font = [UIFont systemFontOfSize:12];
    textLable.textColor = [UIColor RGBColor:140 green:140 blue:140 alpha:1];
    textLable.userInteractionEnabled = NO;
    textLable.backgroundColor = [UIColor clearColor];
    [textView addSubview:textLable];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{

    NSInteger row = 0;
    switch (indexPath.row)
    {
        case 0:
            row =  100;
            break;
        case 1:
            row = 50;
            break;
        case 2:
            row = 70;
            break;
        default:
            break;
    }
    return row;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // 取消选中状态
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

- (void)textViewDidChange:(UITextView *)textView
{
    if ([textView isEqual:_textView1]) {
        if (textView.text.length == 0) {
            _textLable1.text = @"请简单描述你所遇到的问题或建议,还可以添加QQ或者微信账号229201093与我们及时沟通哟~\n";
        }else{
            _textLable1.text = @"";
        }
    }else{
        if (textView.text.length == 0) {
            _textLable2.text = @"填写 QQ 电话 或 邮箱\n";
        }else{
            _textLable2.text = @"";
        }
    }
  
}
#pragma - mark - 懒加载
- (UILabel *)textLable1
{
    if (!_textLable1) {
        _textLable1 = [[UILabel alloc] init];
    }
    return _textLable1;
}

- (UILabel *)textLable2
{
    if (!_textLable2) {
        _textLable2 = [[UILabel alloc] init];
    }
    return _textLable2;
}
- (UITextView *)textView1
{
    if (!_textView1) {
        _textView1 = [[UITextView alloc] init];
    }
    return _textView1;
}
- (UITextView *)textView2
{
    if (!_textView2) {
        _textView2 = [[UITextView alloc] init];
    }
    return _textView2;
}

#pragma mark - 内容警告触发方法
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    [[SDImageCache sharedImageCache] clearMemory];
}
@end
